package com.example.user.controller;

import com.example.common.util.core.controller.BaseController;
import com.example.common.util.core.resultbody.AjaxResult;
import com.example.model.domain.entity.user.UserInfo;
import com.example.model.vo.user.UserInfoQueryVo;
import com.example.user.service.UserInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 用户Controller
 *
 * @author ruoyi
 * @date 2021-07-15
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/admin/user/userInfo")
public class UserInfoController extends BaseController
{
    @Autowired
    private UserInfoService userInfoService;


    //用户列表（条件查询带分页）
    @ApiOperation("用户分页数据")
    @PostMapping("page/{pageNum}/{pageSize}")
    public AjaxResult getUserInfoPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize,@RequestBody UserInfoQueryVo userInfoQueryVo) {
        PageInfo<UserInfo> userInfoPage = userInfoService.getUserInfoPage(pageNum, pageSize, userInfoQueryVo);
        return AjaxResult.success(userInfoPage);
    }


    //用户锁定
    @ApiOperation("锁定用户")
    @PostMapping("lock/{userId}/{status}")
    public AjaxResult lockedUser(@PathVariable Long userId,@PathVariable Integer status) {
        return toAjax(userInfoService.lockedUserById(userId,status));
    }


    //用户详情
    @GetMapping("show/{userId}")
    public AjaxResult getUserInfoDetails(@PathVariable Long userId) {
        Map<String,Object> map = userInfoService.getUserInfoDetailsById(userId);
        return AjaxResult.success(map);
    }


    //认证审批用户
    @ApiOperation("认证审批用户")
    @GetMapping("approval/{userId}/{authStatus}")
    public AjaxResult approveUserInfo(@PathVariable Long userId,@PathVariable Integer authStatus) {
        return toAjax(userInfoService.approveUserInfoById(userId,authStatus));
    }


}
